/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * 
 * 			http://www.kkkd.com/
 * 
 * ========================================================
 */
package com.simon.mengkou.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.simon.mengkou.R;
import com.simon.mengkou.data.bean.base.Discovery;
import com.simon.mengkou.data.bean.base.Image;
import com.simon.mengkou.data.bean.base.Topic;
import com.simon.mengkou.system.global.OuerApplication;
import com.simon.mengkou.system.global.OuerDispatcher;
import com.simon.mengkou.ui.view.HorizontalListView;
import com.simon.mengkou.utils.UtilOuer;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author : Zhenshui.Xia
 * @since : 2016/3/14.
 * desc    : 首页话题适配器
 */
public class HomeTopicAdapter extends AbsAdapter<Topic> {

    public HomeTopicAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        final Holder holder;
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.layout_home_topic_item, null);
            holder = new Holder();
            convertView.setTag(holder);
            ButterKnife.bind(holder, convertView);
        } else {
            holder = (Holder) convertView.getTag();
        }

        final Topic data = getItem(position);

        //打开话题详情
        holder.mRlRoot.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                OuerDispatcher.presentWebTopicDetailActivity(mContext, data.getId());
            }
        });

        //设置banner图片
        Image image = data.getImage();
//        if(image.getWidth() != 0 && image.getHeight()!= 0) {
//            holder.mSdvImage.setAspectRatio(image.getWidth() * 1f / image.getHeight());
//        }

        OuerApplication.mImageLoader.loadImage(holder.mSdvImage, image.getUrl());

        //标题
//        holder.mTvTitle.setText(data.getTitle());
        //日期
//        holder.mTvDate.setText(UtilOuer.formatDate2(data.getDate()));

        return convertView;
    }


    /**
     * @author zhenshui.xia
     */
    class Holder {
        //
        @Bind(R.id.topic_id_root)
        RelativeLayout mRlRoot;
        //话题图片
        @Bind(R.id.topic_id_image)
        SimpleDraweeView mSdvImage;
        //标题
//        @Bind(R.id.topic_id_title)
//        TextView mTvTitle;
        //日期
//        @Bind(R.id.topic_id_date)
//        TextView mTvDate;
    }
}
